﻿
namespace MuddyBoots.Greenlight.QC.Common.Logging
{
    using log4net;
    using System;
    using System.Reflection;


    /// <summary>
    /// Handles logging functionality
    /// </summary>
    public class GlobalLogger
    {
        /// <summary>
        /// The logger
        /// </summary>
        private static readonly ILog Log = LogManager.GetLogger(Assembly.GetEntryAssembly().GetType());

        /// <summary>
        ///     static holder for instance, we need to use a lambda to invoke the private constructor
        /// </summary>
        private static readonly Lazy<GlobalLogger> Lazy = new Lazy<GlobalLogger>(() => new GlobalLogger());

        /// <summary>
        /// The locker
        /// </summary>
        private readonly object locker;

        /// <summary>
        /// Prevents a default instance of the <see cref="GlobalLogger"/> class from being created.
        /// </summary>
        private GlobalLogger()
        {
            this.locker = new object();
        }

        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static GlobalLogger Instance
        {
            get
            {
                return Lazy.Value;
            }
        }

        /// <summary>
        /// Gets the logger.
        /// </summary>
        /// <value>
        /// The logger.
        /// </value>
        public ILog Logger
        {
            get
            {
                lock (this.locker)
                {
                    return Log;
                }
            }
        }

        /// <summary>
        /// Configures the logger from the specified configuration file.
        /// </summary>
        public void Configure()
        {
            log4net.Config.XmlConfigurator.Configure();
        }
    }
}
